var app = getApp();
Page({

  data: {
    UserImage: '',
    Username: '',
    map_width: 300,
    map_height:600
  },

  onLoad: function (options) {
    var that = this;

    app.getLocationInfo(function (locationInfo) {
      console.log('map', locationInfo);
      that.setData({
        longitude: locationInfo.longitude
        , latitude: locationInfo.latitude
        , markers: [
          {
            id: 0
            , iconPath: "/image/location.png"
            , longitude: locationInfo.longitude
            , latitude: locationInfo.latitude
            , width: 30
            , height: 30
          }
        ]
      })
    });
    wx.getSystemInfo({
      success: function (res) {
        console.log('getSystemInfo');
        console.log(res.windowWidth);
        that.setData({
          map_width: res.windowWidth
          , map_height: res.windowWidth
          , controls: [{
            id: 1,
            iconPath: '/image/location.png',
            position: {
              left: res.windowWidth / 2 - 8,
              top: res.windowWidth / 2 - 16,
              width: 30,
              height: 30
            },
            clickable: true
          }]
        })
      }
    })
  },

  getLngLat: function () {
    var that = this;
    this.mapCtx = wx.createMapContext("map4select");
    this.mapCtx.getCenterLocation({
      success: function (res) {

        that.setData({
          longitude: res.longitude
          , latitude: res.latitude
          , markers: [
            {
              id: 0
              , iconPath: "../../imgs/ic_position.png"
              , longitude: res.longitude
              , latitude: res.latitude
              , width: 30
              , height: 30
            }
          ]
        })

      }
    })
  },
  regionchange(e) {
    // 地图发生变化的时候，获取中间点，也就是用户选择的位置
    if (e.type == 'end') {
      this.getLngLat()
    }
  },
  markertap(e) {
    console.log(e)
  },
  about: function () {
    wx.navigateTo({
      url: '../../pages/about/about',
    })
  },
  openResume: function () {
    wx.navigateTo({
      url: '../../pages/resume/resume',
    })
  },
  openRecord: function () {
    wx.navigateTo({
      url: '../../pages/record/record',
    })
  },
  openCollect: function () {
    wx.navigateTo({
      url: '../../pages/collect/collect',
    })
  },
  openIdea: function () {
    wx.navigateTo({
      url: '../../pages/idea/idea',
    })
  }


})